package com.ohs.ohsoa.system.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.MeetingroomDto;
import com.ohs.ohsoa.system.service.MeetingroomService;
import com.ohs.ohsoa.system.vo.MeetingroomVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 *会议室
 *
 * @author qhuang
 * @since 2021-11-10
 */
@Api(value = "会议室controller", tags = "会议室")
@RestController
@RequestMapping(value = "/meetingroom")
public class MeetingroomController {

    @Resource
    private MeetingroomService meetingroomService;

    /**
     * 获取会议室列表信息
     *
     * @param pageParam 检索用参数
     * @return 会议室列表信息
     */
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取会议室列表信息")
    public ResultBean<PageInfo<MeetingroomVo>> meetingroomSelectList(@RequestBody PageParam<MeetingroomDto> pageParam) {
        List<MeetingroomVo> res = meetingroomService.meetingroomSelectList(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }

    /**
     * 根据会议室id查询会议室信息
     * @param meetingroomDto 会议室id数据
     * @return 会议室信息
     */
    @UserLoginToken
    @PostMapping(value = "/select")
    @ApiOperation(httpMethod = "POST", value = "根据会议室id查询会议室信息")
    public ResultBean<MeetingroomVo> meetingroomSelect(@RequestBody MeetingroomDto meetingroomDto){
        return ResultBean.success(meetingroomService.meetingroomSelect(meetingroomDto));
    }

    /**
     * 新增会议室信息
     * @param meetingroomDto 会议室信息数据
     * @return 新增结果
     */
    @UserLoginToken
    @PostMapping(value = "/insert")
    @ApiOperation(httpMethod = "POST", value = "新增会议室信息")
    public ResultBean<Boolean> meetingroomInsert(@RequestBody @Valid MeetingroomDto meetingroomDto, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(meetingroomService.meetingroomInsert(meetingroomDto));
    }

    /**
     * 删除会议室
     * @param meetingroomDto 会议室信息数据
     * @return 删除结果
     */
    @UserLoginToken
    @DeleteMapping(value = "/delete")
    @ApiOperation(httpMethod = "DELETE", value = "删除会议室")
    public ResultBean<Boolean> meetingroomDelete(@RequestBody MeetingroomDto meetingroomDto){
        return ResultBean.success(meetingroomService.meetingroomDelete(meetingroomDto));
    }

    /**
     * 修改会议室信息
     * @param meetingroomDto 会议室信息数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改会议室信息")
    public ResultBean<Boolean> meetingroomUpdate(@RequestBody @Valid MeetingroomDto meetingroomDto,BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(meetingroomService.meetingroomUpdate(meetingroomDto));
    }

    /**
     * 下拉列表信息
     * @param meetingroomDto 会议室信息数据
     * @return 会议室信息
     */
    @UserLoginToken
    @PostMapping(value = "/droplist")
    @ApiOperation(httpMethod = "POST", value = "下拉列表信息")
    public ResultBean<List<MeetingroomVo>> meetingroomDrop(@RequestBody MeetingroomDto meetingroomDto){
        return ResultBean.success(meetingroomService.meetingroomDrop(meetingroomDto));
    }

}
